package com.mall.service.marketing.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.SmsHomeAdvertise;
import com.mall.service.marketing.service.HomeAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName HomeController
 * @Description 广告控制器
 * @Author Young
 * @Date 2023/3/12 13:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/home/advertise")
public class HomeAdvertiseController {

    @Autowired
    private HomeAdvertiseService homeAdvertiseService;

    /**
     * 添加广告
     * @param sha
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsHomeAdvertise sha){
        homeAdvertiseService.create(sha);
        return CommonResult.success(1,"");
    }

    /**
     * 删除广告
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Integer> ids){
        homeAdvertiseService.delete(ids);
        return CommonResult.success(1,"");
    }

    /**
     * 分页查询广告
     * @param endTime
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsHomeAdvertise>> list(String endTime, String name,Integer pageNum, Integer pageSize,Integer type){
        CommonPage page = homeAdvertiseService.myList(endTime,name,pageNum,pageSize,type);
        return CommonResult.success(page);
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable Integer id,Integer status){
        System.out.println(id+"   "+status);
        homeAdvertiseService.updateStatus(id,status);
        return CommonResult.success(1,"修改成功");
    }

    /**
     * 修改广告
     * @param id
     * @param smsHomeAdvertise
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Integer id,@RequestBody SmsHomeAdvertise smsHomeAdvertise){
        homeAdvertiseService.myUpdate(id,smsHomeAdvertise);
        return CommonResult.success(1,"修改成功");
    }

    /**
     * 获取广告详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult getInfo(@PathVariable Integer id){
        SmsHomeAdvertise smsHomeAdvertise = homeAdvertiseService.getInfo(id);
        return CommonResult.success(smsHomeAdvertise,"修改成功");
    }


}
